import com.ugc.harmony.clientai.lang.model.engine.LangEngineCallback
import com.ugc.harmony.clientai.lang.model.engine.LangEnginePerfCallback
import com.ugc.harmony.clientai.lang.request.GenerateParams
import com.ugc.harmony.clientai.lang.request.PerfParams
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import platform.posix.usleep


fun main() {
    val customParams = GenerateParams(
        maxLength = 150,        // 覆盖默认的 max_length
        temperature = 0.7,      // 覆盖默认的 temperature
        topK = 30,              // 覆盖默认的 top_k
        doSample = true,        // 覆盖默认的 do_sample
        randomSeed = 0
    )

    val msInfer: MSLiteLLMInfer = MSLiteLLMInfer("/path/to/model", customParams.toMap(), true)

    var outputPerf: PerfParams = PerfParams()
    val callback = object : LangEnginePerfCallback {
        override fun onPerformance(perfString: String) {
            // 可以添加解析 perfString 的逻辑
            outputPerf = PerfParams.fromPerfString(perfString)
            outputPerf.printParams()
            println("LangEnginePerfCallback  11111")
        }
    }
    // outputPerf.printParams()
    val input = "this is a input text"
    var output = msInfer.generate(input);
    println("output1 is $output \n")
    output = msInfer.generate(input, callback);
    println("output2 is $output \n")
    println("-------------------------------")
    // 2. 创建测试回调实现
    val testCallback = object : LangEngineCallback {



        override fun onReceive(output: String, isEnd: Boolean) {
            println("收到输出: '$output', 是否结束: $isEnd")
            if (isEnd) {
                println("predict is end.")
            }
        }

        override fun onError(error: String) {
            println("发生错误: $error")

        }
    }
    msInfer.generateAsync("this is a test input text", testCallback)
    // msInfer.dispose();
    usleep(2000000u)
    msInfer.stopGenerating()
    usleep(10000000u)

}